﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using thinger.VisionModels;

namespace thinger.VisionDemo
{
    public partial class FrmEditMap : Form
    {
        private SysConfig sysConfig;
        private string BasePath = Application.StartupPath + "\\mapping";
        public FrmEditMap(SysConfig sysConfig)
        {
            this.sysConfig = sysConfig;
            InitializeComponent();
        }

        private void FrmEditMap_Load(object sender, EventArgs e)
        {
            this.numer_check_col.Value = this.sysConfig.numer_check_col;
            this.numer_check_row.Value = this.sysConfig.numer_check_row;
            this.txt_gong_type.Text = this.sysConfig.txt_gong_type;
            this.txt_ke_type.Text = this.sysConfig.txt_ke_type;
            this.txt_model_name.Text = this.sysConfig.dama_model_name;
            this.txt_user_code.Text = this.sysConfig.dama_user_code;
            this.txt_dama_pici.Text = this.sysConfig.dama_pici;
            this.txt_liushui.Text = this.sysConfig.dama_liushui;
            this.numer_liushui.Value = Convert.ToDecimal(this.sysConfig.dama_numer_liushui.ToString());
            this.txt_dama_ver.Text = this.sysConfig.dama_ver;
            //
            this.txt_lotcode.Text = this.sysConfig.lotcode;
            this.txt_okcode.Text = this.sysConfig.okcode;
            this.txt_ngcode.Text = this.sysConfig.ngcode;
            this.txt_frontdata.Text = this.sysConfig.frontdata;
            //
            chc_mapping.Checked = this.sysConfig.chc_mapping;
            //---
            if (string.IsNullOrEmpty(this.sysConfig.cellx))
            {
                this.num_cellx.Value = 0;
            }
            else
            {
                this.num_cellx.Value = Convert.ToDecimal(this.sysConfig.cellx.ToString());
            }
            if (string.IsNullOrEmpty(this.sysConfig.celly))
            {
                this.num_celly.Value = 0;
            }
            else
            {
                this.num_celly.Value = Convert.ToDecimal(this.sysConfig.celly.ToString());
            }
            if (string.IsNullOrEmpty(this.sysConfig.stepx))
            {
                this.num_stepx.Value = 0;
            }
            else
            {
                this.num_stepx.Value = Convert.ToDecimal(this.sysConfig.stepx.ToString());
            }
            if (string.IsNullOrEmpty(this.sysConfig.stepy))
            {
                this.num_stepy.Value = 0;
            }
            else
            {
                this.num_stepy.Value = Convert.ToDecimal(this.sysConfig.stepy.ToString());
            }
            //this.num_celly.Value = Convert.ToDecimal(this.sysConfig.celly.ToString());
            //this.num_stepx.Value = Convert.ToDecimal(this.sysConfig.stepx.ToString());
            //this.num_stepy.Value = Convert.ToDecimal(this.sysConfig.stepy.ToString());
            this.txt_timestyle.Text = this.sysConfig.timestyle;
            //
            this.textBox1.Text = this.sysConfig.var1;
            this.textBox2.Text = this.sysConfig.var2;
            this.textBox3.Text = this.sysConfig.var3;
            this.textBox4.Text = this.sysConfig.var4;
            this.textBox5.Text = this.sysConfig.var5;
            this.textBox6.Text = this.sysConfig.var6;
            this.textBox7.Text = this.sysConfig.var7;
            this.textBox8.Text = this.sysConfig.var8;
            this.textBox9.Text = this.sysConfig.var9;
            this.textBox10.Text = this.sysConfig.var10;
            this.textBox11.Text = this.sysConfig.var11;
            this.textBox12.Text = this.sysConfig.var12;

        }

        private void btn_openpath_Click(object sender, EventArgs e)
        {
            Directory.CreateDirectory(BasePath);

            //MessageBox.Show(path);
            System.Diagnostics.Process.Start("explorer.exe", BasePath);
        }



        private void FrmEditMap_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.sysConfig.chc_mapping = chc_mapping.Checked;
            //
            this.sysConfig.numer_check_col = Convert.ToInt32(this.numer_check_col.Value);
            this.sysConfig.numer_check_row = Convert.ToInt32(this.numer_check_row.Value);
            this.sysConfig.txt_gong_type = this.txt_gong_type.Text.Trim();
            this.sysConfig.txt_ke_type = this.txt_ke_type.Text.Trim();
            //
            this.sysConfig.dama_model_name = this.txt_model_name.Text.Trim();
            this.sysConfig.dama_user_code = this.txt_user_code.Text.Trim();
            this.sysConfig.dama_pici = this.txt_dama_pici.Text.Trim();
            this.sysConfig.dama_liushui = this.txt_liushui.Text.Trim();
            this.sysConfig.dama_numer_liushui = Convert.ToInt32(this.numer_liushui.Text.Trim());
            this.sysConfig.dama_ver = this.txt_dama_ver.Text.Trim();
            //
            this.sysConfig.lotcode = this.txt_lotcode.Text.Trim();
            this.sysConfig.okcode = this.txt_okcode.Text.Trim();
            this.sysConfig.ngcode = this.txt_ngcode.Text.Trim();
            this.sysConfig.frontdata = this.txt_frontdata.Text.Trim();
            //---
            this.sysConfig.cellx = this.num_cellx.Value.ToString().Trim();
            this.sysConfig.celly = this.num_celly.Value.ToString().Trim();
            this.sysConfig.stepx = this.num_stepx.Value.ToString().Trim();
            this.sysConfig.stepy = this.num_stepy.Value.ToString().Trim();
            this.sysConfig.timestyle = this.txt_timestyle.Text.Trim();
            //
            this.sysConfig.var1 = this.textBox1.Text.Trim();
            this.sysConfig.var2 = this.textBox2.Text.Trim();
            this.sysConfig.var3 = this.textBox3.Text.Trim();
            this.sysConfig.var4 = this.textBox4.Text.Trim();
            this.sysConfig.var5 = this.textBox5.Text.Trim();
            this.sysConfig.var6 = this.textBox6.Text.Trim();
            this.sysConfig.var7 = this.textBox7.Text.Trim();
            this.sysConfig.var8 = this.textBox8.Text.Trim();
            this.sysConfig.var9 = this.textBox9.Text.Trim();
            this.sysConfig.var10 = this.textBox10.Text.Trim();
            this.sysConfig.var11 = this.textBox11.Text.Trim();
            this.sysConfig.var12 = this.textBox12.Text.Trim();

            Mainpro.Instance.DoMapChangeMsg();
        }
    }
}
